import { createRouter, createWebHistory } from 'vue-router';
import Layout from '../components/Layout.vue';
import Login from '../views/Login.vue';
import Register from '../views/Register.vue';

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
  },
  {
    path: '/register',
    name: 'Register',
    component: Register,
  },
  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/user-management',
    children: [
      {
        path: 'user-management',
        name: 'UserManagement',
        component: () => import('../views/admin/User.vue'),
        meta: { requiresAuth: true, permissions: ['admin'] },
      },
      {
        path: 'flowertype-management',
        name: 'FlowerTypeManagement',
        component: () => import('../views/admin/FlowerTypeManagement.vue'),
        meta: { requiresAuth: true, permissions: ['admin'] },
      },
      {
        path: 'flower-management',
        name: 'FlowerManagement',
        component: () => import('../views/admin/FlowerManagement.vue'),
        meta: { requiresAuth: true, permissions: ['admin'] },
      },

      {
        path: 'comment-management',
        name: 'CommentManagement',
        component: () => import('../views/admin/CommentManagement.vue'),
        meta: { requiresAuth: true, permissions: ['admin'] },
      },
    ],
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('../views/user/Home.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },
      {
        path: 'detail',
        name: 'Detail',
        component: () => import('../views/user/Detail.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },
      {
        path: 'cart',
        name: 'Cart',
        component: () => import('../views/user/Cart.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },
      {
        path: 'order',
        name: 'Order',
        component: () => import('../views/user/Order.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },
      {
        path: 'my',
        name: 'My',
        component: () => import('../views/user/My.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },
      {
        path: 'myorder',
        name: 'MyOrder',
        component: () => import('../views/user/MyOrder.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },
      {
        path: 'address',
        name: 'Address',
        component: () => import('../views/user/Address.vue'),
        meta: { requiresAuth: true, permissions: ['user'] },
      },

    ]
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

export default router;